<?php include load_template('_subnav.php')?>
<style type="text/css" media="screen">
/* <![CDATA[ */
    div.acl {
        float:left;
        width:200px;
        margin:4px;
        padding:2px;
        border:1px dashed #e9e9e9;
    }
    .acl_perms {
        font-size:xx-small;
        height:20px;
        line-height:20px;
    }    

/* ]]> */
</style>
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
    
    function reload_permissions(user_id)
    {
        new Ajax.Updater('user_permissions','<?php echo url_for(array('controller'=>'admin/users','action'=>'get_user_permissions')) ?>
        ',{parameters:'user_id='+user_id});
    }
// ]]>
</script>
<h1>User Management</h1>

<h3><?php echo link_to('Add New User',array('controller'=>'admin/users' )
)?></h3>

<!-- Select User To Manage -->
<div id="select_new">
<?php echo form_tag('index',array('method'=>'get'))?>
Get Details For: <?php echo select_tag('id',options_for_select($all_users, (int) @$_REQUEST['id']))?>
<?php echo submit_tag('Edit')?>
<?php echo end_form_tag()?>
</div>


<?php echo error_messages_for('users')?>
<h2><?php if(!empty($user)) echo "Managing User: <span style='color:red'>{$user['first_name']} {$user['last_name']}</span>" ?></h2>
<?php
    if ( empty($user) )
    {
?>
<div id="tabPanel1" class='tab-pane'>    
        <div id="tabPage1" class='tab-page'>
        <h2 class='tab'>Add User</h2>      
        <?php echo form_tag('index',array('validation'=>true))?>
        <?php echo hidden_field_tag('action','add_user')?>
        <?php include load_template('_form.php')?>
        <?php echo end_form_tag()?>
    </div>
</div>
<?php } else { ?>
  <div id="tabPanel" class='tab-pane'>    
    <div id="tabPage1" class='tab-page'>
        <h2 class='tab'>Edit user details</h2>
        <?php echo form_tag('index',array('validation'=>true))?>
        <?php echo hidden_field_tag('action','edit_user')?>
        <?php include load_template('_form_edit.php')?>
        <?php echo end_form_tag()?>
        
        <div class='div-delete'>
        <?php echo  form_tag('delete') ?>
        <?php echo  hidden_field_tag('id',$user['id']) ?>
        <?php echo  hidden_field_tag('action','delete') ?>
        <span style='color:red;font-weight:bold'>Delete This User?</span>
        <?php echo  submit_tag('Delete User',array('confirm'=>'Are you sure you want to delete this user?','class'=>'submit_delete')) ?>
        <?php echo  end_form_tag() ?>
        </div>
    </div>
    
    <div id="tabPage2" class='tab-page'>
        <h2 class='tab'>Roles this user has</h2>
        <div class='user_roles' style='width:350px;'>
        <?php echo form_remote_tag(array('controller'=>'admin/roles' ,'action'=>'modify_user_roles'),
                array(
                    'name'=>'user_roles',
                    'update'=>'success_messages',
                    'before'=>"selectAll('roles[]')",
                    'complete'=>"toggle_success();reload_permissions({$user['id']});",
                    )
                    )
         ?>
        <?php echo hidden_field_tag('user_id', $user['id'])?>
        <?php echo select_transfer('roles[]', array_diff($all_roles,$user_roles), $user_roles)?>  
        <p><?php echo submit_tag('Modify Roles')?></p>
        <?php echo end_form_tag()?>
       </div>
    </div>
    
    <div id="tabPage3" class='tab-page'>
        <h2 class='tab'>Permissions for this user</h2>
        <div id='user_permissions'>
<!--    radio buttons   -->
        <?php include load_template('_permissions.php')?>
        <br style='clear:both'>
        </div>
    </div>
    </div>
<?php } ?>

    <script type="text/javascript">
        setupAllTabs();
    </script>
